package it.yuzuojian.com.service.impl;

import it.yuzuojian.com.dao.ConsumerMapper;
import it.yuzuojian.com.domain.Consumer;
import it.yuzuojian.com.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConsumerServiceImpl implements ConsumerService {
    @Autowired
    private ConsumerMapper consumerMapper;
    @Override
    public Boolean insert(Consumer consumer) {
        return consumerMapper.insert(consumer)>0;
    }

    @Override
    public Boolean update(Consumer consumer) {
        return consumerMapper.update(consumer)>0;
    }

    @Override
    public Boolean delete(Integer[] ids) {
        Boolean flag=true;
        for (Integer id : ids) {
            System.out.println(id);
            if(consumerMapper.delete(id)==0){
                flag=false;
            }
        }
        return flag;
    }

    @Override
    public Consumer selectById(Integer id) {
        return consumerMapper.selectById(id);
    }

    @Override
    public List<Consumer> selectAll() {
        return consumerMapper.selectAll();
    }

    @Override
    public List<Consumer> selectByUsername(String username) {
        username="%"+username+"%";
        return consumerMapper.selectByUsername(username);
    }

    @Override
    public Consumer selectOneByUsername(String username) {
        return consumerMapper.selectOneByUsername(username);
    }




}
